package com.zgm.utils;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 张公铭 on 2017/6/19 0019.
 * 时间工具类
 */

public class DateUtils
{
    private static DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Timestamp getCurrentTime()
    {
        return new Timestamp(System.currentTimeMillis());
    }

    public static String formatCurrentTime()
    {
        String time = format.format(new Date(System.currentTimeMillis()));
        return time;
    }

    /**
     * 是否小于系统当前时间
     */
    public static boolean isBefor(long time)
    {
        long curTime = System.currentTimeMillis();
        if (curTime >= time)
        {
            return false;
        }
        return true;
    }

    /**
     * 获取当前小时
     */
    public static String getHour(long time)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
        String hour = sdf.format(new Date(time));
        return hour;
    }

    public static String formatTime(long time)
    {
        String date = format.format(new Date(time));
        return date;
    }

    public static String formateTime(long time, String style)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(style);
        String values = sdf.format(new Date(time));
        return values;
    }
}
